<template>
<div>
  <div class="detail-box detail-width">
    <!-- <detail-left v-show="currentView=='DetailMiddle'"></detail-left> -->
    <!-- <detail-left></detail-left> -->

    <!-- <detail-Middle></detail-Middle> -->
    <!-- <detail-Selector></detail-Selector> -->
    <detail-Desc :detailNews="detailNews" :detailNewsContent="detailNewsContent" :mainId="mainId" :comments='comments' :hasComment="hasComment"></detail-Desc>
    <!-- <component @getview="getviews" :is="currentView" :details="currentView"></component> -->
    <!-- <detail-middle></detail-middle> -->
    <detail-right :right="currentView" :childShow="isShow" :hasLogin="hasLogin"></detail-right>
  </div>
</div>
</template>
<script>
import Service from '@/service/service'
// import DetailLeft from "./components/DetailLeft";
// import DetailMiddle from "./components/DetailMiddle";
import DetailRight from "./components/DetailRight";
// import DetailSelector from "./components/DetailSelector";
import DetailDesc from "./components/DetailDesc";
// import axios from 'axios'
export default {
  name: "JobDetail",
  components: {
    // DetailLeft,
    // DetailMiddle,
    DetailRight,
    // DetailSelector,
    DetailDesc
  },
  data() {
    return {
      currentView: "DetailMiddle",
      isShow:'',
			userId:sessionStorage.getItem("userId")||0,
      detailNews:{},
      detailNewsContent:{},
      mainId:'',
      comment:'',
      comments:'',
      hasComment:false,
      hasLogin:false,
      // currentView: "DetailDesc",
    };
  },
  created(){
    // this.getD();
    // 首次查询咨询详情
    const nid = this.$router.history.current.query.id;
    this.getNewsDetail(nid)
  },
  methods: {
    getviews(val) {
      // if(val==2){
      //   this.$nextTick(function () {
      this.currentView = "DetailSelector";
      // })
    },
    getNewsDetail (data){
      // 获取咨询详情
      let _this = this;
      let newsId = data;
      // 获取咨询详情
			let indData = {
        param: {
          id: newsId
        },
        userId: this.userId
      };
      Service.myAjax(
        {
        method: "post",
        url: Service.baseUrl + "/news/detailNewsContent",
        data: indData
        },
        function(response) {
          const {data} = response.data;
          console.log(data)
          _this.detailNews = data.detailNews;
          _this.detailNewsContent = data.detailNewsContent;
          _this.mainId= data.detailNews.id;
          _this.searchComments(data.detailNews.id)
        },
        function(error) {
          console.log(error)
        }
      )
    },
    searchComments (mid){
      // 查询文章对应的评论
      let _this = this;
      // 获取咨询详情
      let data = {
        param: {
          detail:{
            comment:this.comment,
            mainId: mid,
            pageNo:1,
            pageSize: 10
          }
        },
        userId: this.userId
      };
      Service.myAjax(
        {
          method: "post",
          url: Service.baseUrl + "/dynamic/searchComments",
          data: data
        },
        function(response) {
          const {data} = response.data;
          console.log(data)
          _this.comments = data.list;
          if(data.list.length>0){
            // 评论数>0
            _this.hasComment = true;
          }else{
            _this.hasComment = false;
          }
        },
        function(error) {
          console.log(error)
        }
      )

    },
  },
  watch:{
      "$route":{
        handler: function(val, oldVal){
          let result = val.query.Detail;
          this.newsId = val.query.id;
          this.getNewsDetail(this.newsId)
          if(result){
            this.isShow = result
            this.currentView = result;
          }else{
            this.isShow = '';
          }
        },
        // 深度观察监听
        deep: true
      }
    }
};
</script>
<style lang="stylus" scoped>
.detail-box {
  display: flex;
  justify-content: space-around;
}

.detail-box.detail-width {
  justify-content: flex-end;
  width: 1260px;
  margin: 0 auto;
}
</style>
